<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Comment extends BaseModel
{
    protected $fillable = [
        'parentId',
        'userId',
        'atUserId',
        'questionId',
        'content',
        'like',
    ];

    public function children(): HasMany
    {
        return $this->hasMany(Comment::class, 'parentId');
    }

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
    ];

    public function parent(): BelongsTo
    {
        return $this->belongsTo(Comment::class, 'parentId');
    }
}
